<?php
	header("Content-Type: text/html;charset=utf-8");
	include("function/_nosql.php"); //
	include("function/function.php");
	$kboy_userid = $_SESSION['kboy_userid'];
	if(!$kboy_userid)$kboy_userid=0;
	$kboy_user = $_SESSION['kboy_user'];
	$action = chkstr(trim($_REQUEST['action']));
	$strhtml = chkstr(trim($_REQUEST['strhtml'])); 
	$pid = chkstr(trim($_REQUEST['pid']));
	$tid = chkstr(trim($_REQUEST['tid']));
	$ip = getip();
	$ch = curl_init();
    $url = 'http://apis.baidu.com/apistore/iplookupservice/iplookup?ip='.$ip;
    $header = array(
        'apikey: 832ae83d5e32315fdcac763f7047621f',
    );
    // 添加apikey到header
    curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 执行HTTP请求
    curl_setopt($ch , CURLOPT_URL , $url);
    $res = curl_exec($ch);
	if($re->errNum == 1){
			erro('您的IP未被检测出来，请重新发送');
		}
    $re = json_decode($res);
	if(IS_AJAX){
		$dizhi = $re->retData->province;
		if($action == 'add'){
		if(empty($strhtml)){
			erro('请输入评论内容');
		}
		
		$mysql = new sqlstr("kboy_forum_travel_message"); 
		$mysql -> set("tid",$tid,true);
		$mysql -> set("uid",$kboy_userid);
		$mysql -> set("news_text",$strhtml);
		$mysql -> set("youkeip",$dizhi);
		$add_sql = $mysql -> insertSql(); 
		$add_re = mysql_query($add_sql);
		if($add_re){
			echo 1; 
			die;
		}else{
			echo 0;
			die;
		}
		}elseif($action == 'reply'){
		$news_text = $strhtml;
		if(strlen($news_text) < 1){
			erro('评论内容不能为空');
		}
		if(strlen($pid) < 1 || !isNumber($pid)){
			erro('参数错误2');
		}
		
		if(getNewsNums('kboy_forum_travel_message',"id=$pid") < 1){
			erro('参数错误3');
		}
		$tid = getClassName('kboy_forum_travel_message','tid','id='.$pid);
		$mysql = new sqlstr("kboy_forum_travel_message"); 
		$mysql -> set("uid",$kboy_userid,true);
		$mysql -> set("tid",$tid,true);
		$mysql -> set("pid",$pid,true);
		$mysql -> set("news_text",$news_text);
		$mysql -> set("youkeip",$dizhi);
		$add_sql = $mysql -> insertSql();
		$add_re = mysql_query($add_sql);
		if($add_re){
			echo 1;
		}else{
			echo 0;
		}
		
		}else{
			erro("参数错误4");
		}
	}
	